package tuanda.soict.firstsun.TestPackage;

import java.util.ArrayList;

import tuanda.soict.firstsun.AbilityPackage.Ability;
import tuanda.soict.firstsun.DataPackage.ArmyDataSet;
import tuanda.soict.firstsun.DataPackage.AttributeList;
import tuanda.soict.firstsun.DataPackage.CommonConstants;
import tuanda.soict.firstsun.LogicPackage.AI_Part;
import tuanda.soict.firstsun.LogicPackage.Army;
import tuanda.soict.firstsun.LogicPackage.BattleMap;
import tuanda.soict.firstsun.LogicPackage.CompleteActionSet;
import tuanda.soict.firstsun.LogicPackage.Coordinate;
import tuanda.soict.firstsun.LogicPackage.Group;
import tuanda.soict.firstsun.LogicPackage.MovementSet;

/**
 * @author tuanda_soict_hut
 * @version 0.0.1
 * @since 1-8-2012
 */
public class WOTAPrototype implements CommonConstants, AttributeList {

	private AI_Part ai_Part;
	private Group[] group;
	private BattleMap map;

	public void initialize() {
		group = new Group[2];
		group[0] = new Group("Group1", 1, 0, 10000, HUMAN);
		group[1] = new Group("Group2", 2, 1, 10000, HUMAN);

		int k = LAND_TYPE;
		map = new BattleMap(20, 20);
		for (int i = 0; i < map.getNumberOfColumn(); i++) {
			for (int j = 0; j < map.getNumberOfRow(); j++) {
				map.setEnvironment(i, j, "Env_" + i + "_" + j, 0, 0, k);
			}
		}

		int[] playerType = { HUMAN_PLAYER, COMPUTER_PLAYER };
		ai_Part = new AI_Part(map, group, 0, playerType, null);
		ArmyDataSet army = ArmyDataSet.KNIGHT;
		ArmyDataSet army2 = ArmyDataSet.ARCHER;
		ArmyDataSet army3 = ArmyDataSet.ANGEL;
		Ability[] ability1 = new Ability[MAX_NUMBER_SKILL];
		for (int l = 0; l < MAX_NUMBER_SKILL; l++) {
			ability1[l] = Ability.abilityInitializer(army.getSkill(l));
		}
		ai_Part.addNewArmy(army.getName(), 0, army.getRank(), army.getType(),
				army.getMinAttack(), army.getMaxAttack(), army.getDefense(),
				army.getMovement(), army.getAttackRange(),
				army.getGoldRequire(), 0, 0, army.getID(), ability1,
				FIRE_ATTRIBUTE);
		Ability[] ability2 = new Ability[MAX_NUMBER_SKILL];
		for (int l = 0; l < MAX_NUMBER_SKILL; l++) {
			ability2[l] = Ability.abilityInitializer(army2.getSkill(l));
		}
		ai_Part.addNewArmy(army2.getName(), 0, army2.getRank(),
				army2.getType(), army2.getMinAttack(), army2.getMaxAttack(),
				army2.getDefense(), army2.getMovement(),
				army2.getAttackRange(), army2.getGoldRequire(), 1, 0,
				army2.getID(), ability2, FIRE_ATTRIBUTE);
		Ability[] ability3 = new Ability[MAX_NUMBER_SKILL];
		for (int l = 0; l < MAX_NUMBER_SKILL; l++) {
			ability3[l] = Ability.abilityInitializer(army3.getSkill(l));
		}
		ai_Part.addNewArmy(army3.getName(), 0, army3.getRank(),
				army3.getType(), army3.getMinAttack(), army3.getMaxAttack(),
				army3.getDefense(), army3.getMovement(),
				army3.getAttackRange(), army3.getGoldRequire(), 0, 1,
				army3.getID(), ability3, FIRE_ATTRIBUTE);

		ArmyDataSet army4 = ArmyDataSet.CLERIC;
		ArmyDataSet army5 = ArmyDataSet.GRYPHON;
		ArmyDataSet army6 = ArmyDataSet.WIZARD;

		Ability[] ability4 = new Ability[MAX_NUMBER_SKILL];
		for (int l = 0; l < MAX_NUMBER_SKILL; l++) {
			ability4[l] = Ability.abilityInitializer(army4.getSkill(l));
		}

		ai_Part.addNewArmy(army4.getName(), 1, army4.getRank(),
				army4.getType(), army4.getMinAttack(), army4.getMaxAttack(),
				army4.getDefense(), army4.getMovement(),
				army4.getAttackRange(), army4.getGoldRequire(), 2, 3,
				army4.getID(), ability4, FIRE_ATTRIBUTE);

		Ability[] ability5 = new Ability[MAX_NUMBER_SKILL];
		for (int l = 0; l < MAX_NUMBER_SKILL; l++) {
			ability5[l] = Ability.abilityInitializer(army5.getSkill(l));
		}
		ai_Part.addNewArmy(army5.getName(), 1, army5.getRank(),
				army5.getType(), army5.getMinAttack(), army5.getMaxAttack(),
				army5.getDefense(), army5.getMovement(),
				army5.getAttackRange(), army5.getGoldRequire(), 3, 2,
				army5.getID(), ability5, FIRE_ATTRIBUTE);

		Ability[] ability6 = new Ability[MAX_NUMBER_SKILL];
		for (int l = 0; l < MAX_NUMBER_SKILL; l++) {
			ability6[l] = Ability.abilityInitializer(army6.getSkill(l));
		}
		ai_Part.addNewArmy(army6.getName(), 1, army6.getRank(),
				army6.getType(), army6.getMinAttack(), army6.getMaxAttack(),
				army6.getDefense(), army6.getMovement(),
				army6.getAttackRange(), army6.getGoldRequire(), 2, 2,
				army6.getID(), ability6, FIRE_ATTRIBUTE);

		ai_Part.addArmyBuilding("Army1", 0, 0, 0, LAND_TYPE, 30, 20, LAND_TYPE,
				0, 6, 3);
		ai_Part.addArmyBuilding("Army2", 0, 0, 0, LAND_TYPE, 30, 20, LAND_TYPE,
				0, 5, 3);
		ai_Part.addArmyBuilding("Army3", 0, 0, 0, LAND_TYPE, 30, 20, LAND_TYPE,
				0, 4, 3);
		ai_Part.addArmyBuilding("Army4", 0, 0, 0, LAND_TYPE, 30, 20, LAND_TYPE,
				0, 3, 3);
		ai_Part.addArmyBuilding("Army5", 0, 0, 0, LAND_TYPE, 30, 20, LAND_TYPE,
				0, 2, 3);
		ai_Part.addArmyBuilding("Army6", 0, 0, 0, LAND_TYPE, 30, 20, LAND_TYPE,
				0, 1, 3);
		ai_Part.addArmyBuilding("Army2", 1, 0, 0, LAND_TYPE, 30, 20, LAND_TYPE,
				2, 2, 3);

		ai_Part.addHQBuilding("HQ1", 0, 15, 0, LAND_TYPE, 100, 20, 0, 0, 4);
		ai_Part.addHQBuilding("HQ2", 1, 15, 0, LAND_TYPE, 100, 20, 19, 19, 4);
		ai_Part.initialzeEnemyHQ();
		ai_Part.initializeArmyDefense();
	}

	public CompleteActionSet testModule_generate_move() {
		// MovementSet[][] flySet =
		// ai_Part.generateMove(ai_Part.getGroup(0).getArmy(0));
		System.out.println(System.nanoTime());
		CompleteActionSet singleMove = ai_Part.generateSingleMove(ai_Part
				.getGroup(1).getArmy(2), 0);
		MovementSet[][] flySet = ai_Part.getBattleMap().getMovementSet();
		System.out.println(System.nanoTime());

		for (int i = 0; i < flySet.length; i++) {
			for (int j = 0; j < flySet[0].length; j++) {
				System.out.print(" ");
				if (flySet[i][j] != null) {
					System.out.print(flySet[i][j].getLocationX() + "-"
							+ flySet[i][j].getLocationY());
				} else {
					System.out.print("   ");
				}
			}
			System.out.println();
		}
		return singleMove;
	}

	public void print_infomation(Army arm) {
		System.out.println(arm.getName() + " " + arm.getHealth() + " "
				+ arm.getLocationX() + " " + arm.getLocationY() + " ");
	}

	public static void main(String[] args) {
		WOTAPrototype wotap = new WOTAPrototype();
		wotap.initialize();
		CompleteActionSet single = wotap.testModule_generate_move();
		ArrayList<Coordinate> path = single.getMovementPath();
		for (Coordinate coor : path) {
			System.out.println(coor.getLocationX() + "-" + coor.getLocationY());
		}
		Ability temp = single.getAction();
		if (temp != null) {
			System.out.println(temp.getName());
			Coordinate target = temp.getTarget();
			System.out.println(target.getLocationX() + "-"
					+ target.getLocationY());
		}
	}
}
